package com.tzkyzj.tiremanagersystem.api;

import com.tzkyzj.tiremanagersystem.eneities.Tire;
import com.tzkyzj.tiremanagersystem.eneities.TireBatchRequest;
import com.tzkyzj.tiremanagersystem.eneities.TirePhoto;
import com.tzkyzj.tiremanagersystem.network.ApiResponse;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.*;

import java.util.List;
import java.util.Map;

public interface TireApiService {

    @GET("api/tires/search")
    Call<Map<String, Object>> searchTires(
            @Query("tireNumber") String tireNumber,
            @Query("plateNumber") String plateNumber,
            @Query("company") String company,
            @Query("status") String status
    );

    @GET("api/tires/autocomplete/tire-numbers")
    Call<List<String>> autocompleteTireNumbers(@Query("term") String term);

    @GET("api/tires/autocomplete/plate-numbers")
    Call<List<String>> autocompletePlateNumbers(@Query("term") String term);

    // 获取所有运输公司 - 根据你的后端API调整路径
    @GET("api/tires/transport-companies")
    Call<List<String>> getTransportCompanies();

    // 获取状态选项 - 根据你的后端API调整路径
    @GET("api/tires/status-options")
    Call<List<String>> getStatusOptions();


    // 使用原有的Multipart端点
    @Multipart
    @POST("api/tires/batch-add")
    Call<ResponseBody> batchAddTires(@Part List<MultipartBody.Part> parts);

    // 添加测试连接接口
    @GET("/") // 测试根路径
    Call<ResponseBody> testConnection();


    // 新增的API方法
    @GET("api/tires/{tireId}/photos")
    Call<List<TirePhoto>> getTirePhotos(@Path("tireId") Long tireId);


    @POST("api/tires/{tireId}/scrap")
    Call<ApiResponse<Void>> markTireAsScrap(@Path("tireId") Long tireId, @Query("scrapMileage") int scrapMileage);

    @GET("api/tires/{tireId}/photos/{photoId}")
    Call<ResponseBody> getTirePhoto(@Path("tireId") Long tireId, @Path("photoId") Long photoId);


    @Multipart
    @POST("api/tires/android/{tireId}/repair")
    Call<ApiResponse<Void>> addRepairRecord(
            @Path("tireId") Long tireId,
            @Part("repairRecord") RequestBody repairRecord,
            @Part("repairMileage") RequestBody repairMileage,
            @Part("repairCost") RequestBody repairCost,
            @Part List<MultipartBody.Part> repairPhotos
    );

    // 在 TireApiService.java 中添加
    @GET("api/tires/{id}")
    Call<ApiResponse<Tire>> getTireById(@Path("id") Long id);


    @GET("api/tires/android/{id}")
    Call<ApiResponse<Tire>> getTireDetail(@Path("id") Long id);


    // 在 TireApiService 中添加
    // 在 TireApiService.java 中
    @Multipart
    @POST("api/tires/android/{id}/swap")
    Call<ApiResponse<Void>> addSwapRecord(
            @Path("id") Long id,
            @Part("swapDate") RequestBody swapDate,
            @Part("swapMileage") RequestBody swapMileage,
            @Part("swapCost") RequestBody swapCost,
            @Part("fromVehiclePlateNumber") RequestBody fromVehiclePlateNumber,
            @Part("fromTrailerPlateNumber") RequestBody fromTrailerPlateNumber,
            @Part("fromAxleNumber") RequestBody fromAxleNumber,
            @Part("fromTirePosition") RequestBody fromTirePosition,
            @Part("toVehiclePlateNumber") RequestBody toVehiclePlateNumber,
            @Part("toTrailerPlateNumber") RequestBody toTrailerPlateNumber,
            @Part("toAxleNumber") RequestBody toAxleNumber,
            @Part("toTirePosition") RequestBody toTirePosition,
            @Part("swapNote") RequestBody swapNote,
            @Part("operationType") RequestBody operationType,
            @Part("confirmScrap") RequestBody confirmScrap,
            @Part MultipartBody.Part[] swapPhotos  // 改回数组
    );



    @POST("api/auth/login")
    Call<Map<String, Object>> login(@Body Map<String, String> loginData);


    @PUT("api/tires/update")
    Call<Map<String, Object>> updateTire(@Body Map<String, Object> tireData);

    @POST("api/tires/android/update")
    Call<ApiResponse<Void>> updateTireForAndroid(@Body Map<String, Object> tireData);
}